def compare_combinations(combinations_list, existing_combinations, max_duplicate_ratio=0.2):
    """
    对比组合列表与已存在的组合，返回未重复或重复率低于阈值的新组合
    :param combinations_list: 所有生成的组合
    :param existing_combinations: 已存在的组合
    :param max_duplicate_ratio: 最大允许重复字段比例（默认20%）
    :return: 符合条件的新组合列表
    """

    existing_set = set(tuple(map(str, combo)) for combo in existing_combinations)

    def is_combo_allowed(combo):
        combo_tuple = tuple(map(str, combo))
        if combo_tuple in existing_set:
            return False  # 完全重复的组合直接排除

        # 判断字段重复数量
        for existing_combo in existing_combinations:
            existing_tuple = tuple(map(str, existing_combo))
            if len(combo) != len(existing_tuple):
                print(f"{combo_tuple} 和 {existing_tuple} 字段数量不同")
                continue  # 字段数量不同，无法比较，跳过

            duplicate_count = sum(1 for a, b in zip(combo, existing_combo) if a == b)
            duplicate_ratio = duplicate_count / len(combo)

            if duplicate_ratio > max_duplicate_ratio:
                return False  # 超过最大重复率，拒绝该组合
        return True  # 无过高重复，允许使用

    result = [combo for combo in combinations_list if is_combo_allowed(combo)]
    return result


if __name__ == "__main__":
    # 获取命令行参数
    existing_combinations = [["a", "1", "A"], ["a", "2", "B"]]

    combinations_list = [["a", "1", "B"], ["b", "2", "B"], ["c", "3", "A"]]

    ret = compare_combinations(combinations_list, existing_combinations, max_duplicate_ratio=(1/3))
    print(ret)